<template>
  <div class="Dynanic">
    <van-nav-bar
        title="动态"
        left-text="返回"
        left-arrow
        @click-left="onClickLeft"
    />
    <van-tabs v-model:active="activeTab">
      <div class="scroll-container">
        <van-list v-model:loading="loading"  @load="onLoad" :finished-text="finishedText"
                  :error-text="errorText">
          <div class="item" v-for="(item, index) in list1" :key="index">
            <div class="item-header">
              <div class="item-header-left">
                <van-image :src="item.avatar" round width="40" height="40"/>
                <span class="item-header-name">{{ item.userId }}</span>
                <span class="item-header-time">{{ item.createTime }}</span>
              </div>
              <van-tag type="primary" round size="small" v-if="item.hot">hot</van-tag>
            </div>
            <div class="item-content">
              <p>{{ item.content }}</p>
              <div class="image-wrapper">
                <van-image :src="item.contentImg" width="200px" height="100px"/>
              </div>
              <div class="item-footer">
                <van-icon name="like-o" size="16" class="icon"/>
                <span class="icon-text">{{ item.praises }}</span>
                <van-icon name="star-o" size="16" class="icon"/>
                <span class="icon-text">{{ item.review }}</span>
                <van-icon name="chat-o" size="16" class="icon"/>
                <span class="icon-text">{{ item.collect }}</span>
                <van-icon name="share-o" size="16" class="icon"/>
                <span class="icon-text">{{ item.share }}</span>
              </div>
            </div>
          </div>
        </van-list>
      </div>
    </van-tabs>
  </div>
</template>

<script setup>
import {ref} from 'vue'
import {useRouter} from "vue-router";
import axios from "axios";
import {showToast} from "vant";
import {get} from "../../util/request.js";
const router=useRouter();
const finishedText = ref('没有更多了');
const errorText = ref('加载失败，请稍后重试');
const list1 = ref([]);
const onClickLeft = () => {
  router.push("/my");
  // 返回按钮逻辑
};
const activeTab = ref(0);
const loading = ref(true);
const finished = ref(true);
const onLoad = async () => {
  loading.value = true;
  /*const newUsers = await getUsers();*/
  /*  users.value = [...users.value, ...newUsers];*/
  loading.value = false;
  /*if (newUsers.length === 0) {
    finished.value = true;
  }*/
};
get(
  'circle/selectAll'
).then(
    (data) => {
      console.log(JSON.stringify(data))

      // 加载状态结束
      loading.value = false;
      finished.value = true

      if (data.code == 0) {
        showToast("查询成功");
        list1.value = data.data;// 初始化界面
      } else {
        showToast("查询失败");
      }


    })
    .catch(
        function () {
          alert("服务器错误")
        }
    )
</script>

<style scoped>
.Dynanic {
  padding: 16px;
}
</style>